﻿using System;
using System.Collections.Concurrent;

namespace Listing1_30
{
    public static class Program
    {
        public static void Main()
        {
            ConcurrentBag<int> bag = new ConcurrentBag<int>();
            bag.Add(42);
            bag.Add(21);
            bag.Add(42);
            int result;
            if (bag.TryTake(out result))
                Console.WriteLine(result);
            if (bag.TryTake(out result))
                Console.WriteLine("There is a next item: {0}", result);
            if (bag.TryPeek(out result))
                Console.WriteLine("And a third one (repeated): {0}", result);
            Console.ReadKey();
        }
    }
}